package top.lcm889.juc.count_down_latch;

import java.time.LocalDateTime;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * @author Coder-lcm
 * @date 2021/4/30
 */
public class WriterThread implements Runnable {
    private CountDownLatch latch;
    private String name;

    public WriterThread(CountDownLatch latch, String name){
        this.latch = latch;
        this.name = name;
    }

    @Override
    public void run() {
        try {
            System.out.println(LocalDateTime.now() + " " + name + " 等待顾客");
//            latch.await();
            latch.await(3, TimeUnit.SECONDS);//最多等三秒，不来就上菜
            System.out.println(LocalDateTime.now() + " " + name + " 开始上菜");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
